package 每日一题;

import java.util.Scanner;

public class WY22Fibonacci数列 {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int input=sc.nextInt();
        System.out.println(fun(input));
    }


    private static int fun(int input) {
        int a=0;
        int b=1;

        while (b<input) {
            int c=a+b;
            a=b;
            b=c;
        }

        //b >= input
        return Math.min(input-a,b-input);
    }
}
